// https://umijs.org/config/
import { defineConfig, utils } from 'umi';
import defaultSettings from './defaultSettings';
import proxy from './proxy';
import webpackPlugin from './plugin.config';

const { winPath } = utils;

// preview.pro.ant.design only do not use in your production ;
// preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。
const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, REACT_APP_ENV, GA_KEY } = process.env;

export default defineConfig({
  hash: true,
  antd: {},
  analytics: GA_KEY ? { ga: GA_KEY } : false,
  dva: {
    hmr: true,
  },
  locale: {
    // default zh-CN
    default: 'zh-CN',
    // default true, when it is true, will use `navigator.language` overwrite default
    antd: true,
    baseNavigator: true,
  },
  dynamicImport: {
    loading: '@/components/PageLoading/index',
  },
  targets: {
    ie: 11,
  },
  // umi routes: https://umijs.org/docs/routing
  routes: [
    {
      path: '/user',
      component: '../layouts/UserLayout',
      routes: [
        {
          name: 'login',
          path: '/user/login',
          component: './user/login',
        },
      ],
    },

    {
      path: '/demo',
      name: 'demo',
      component: './demo/drag/index.tsx',
    },
    {
      path: '/demo/other',
      name: 'demo',
      component: './demo/other/index.tsx',
    },
    {
      path: '/demo/cls',
      name: 'demo',
      component: './demo/cls/index.tsx',
    },
    {
      path: '/',
      component: '../layouts/SecurityLayout',
      routes: [
        {
          path: '/',
          component: '../layouts/BasicLayout',
          // authority: ['admin', 'user'],
          routes: [
            {
              path: '/',
              redirect: '/main',
            },
            {
              path: '/main',
              name: '首页概况',
              icon: 'home',
              component: './main/index.tsx',
            },
            {
              path: '/admin',
              name: '管理页',
              icon: 'crown',
              component: './Admin',
              authority: ['admin'],
              routes: [
                {
                  path: '/admin/sub-page',
                  name: 'sub-page',
                  icon: 'smile',
                  component: './Welcome',
                  authority: ['admin'],
                },
              ],
            },
            // {
            //   name: 'list.table-list',
            //   icon: 'table',
            //   path: '/list',
            //   component: './ListTableList',
            // },
            {
              path: '/goods',
              name: '商品管理',
              icon: 'carry-out',
              routes: [
                {
                  path: '/goods/list',
                  name: '商品列表',
                  component: './goods/list/index.tsx',
                },
                {
                  path: '/goods/list-save',
                  name: '商品保存',
                  component: './goods/list/save/index.tsx',
                  hideInMenu: true,
                },

                {
                  path: '/goods/category',
                  name: '商品分类',
                  component: './goods/category/index.tsx',
                },
                {
                  path: '/goods/brand',
                  name: '商品品牌',
                  component: './goods/brand/index.tsx',
                },
                {
                  path: '/goods/tag',
                  name: '商品标签',
                  component: './goods/tag/index.tsx',
                },
                {
                  path: '/goods/spec',
                  name: '商品规格',
                  component: './goods/spec/index.tsx',
                },
                {
                  path: '/goods/genre',
                  name: '商品类型',
                  component: './goods/genre/index.tsx',
                },
                {
                  path: '/goods/album',
                  name: '商品相册',
                  component: './goods/album/index.tsx',
                },
                {
                  path: '/goods/album/picture/:albumId',
                  name: '图片管理',
                  component: './goods/album/picture.tsx',
                  hideInMenu: true,
                },
              ],
            },
            {
              path: '/order',
              name: '订单管理',
              icon: 'menu-unfold',
              routes: [
                {
                  path: '/order/list',
                  name: '订单列表',
                  component: './order/list/index.tsx',
                },
                {
                  path: '/order/recharge',
                  name: '充值订单',
                  component: './order/recharge/index.tsx',
                },
                {
                  path: '/order/after-service',
                  name: '售后服务',
                  component: './order/after_service/index.tsx',
                },
                {
                  path: '/order/verification',
                  name: '订单核销',
                  component: './order/verification/index.tsx',
                },
                {
                  path: '/order/trade-setup',
                  name: '交易设置',
                  component: './order/trade_setup/index.tsx',
                },
                {
                  path: '/order/express',
                  name: '配送管理',
                  component: './order/express/index.tsx',
                },
              ],
            },
            {
              path: '/member',
              name: '会员管理',
              icon: 'user',
              routes: [
                {
                  path: '/member/list',
                  name: '会员列表',
                  component: './member/list/index.tsx',
                },
                {
                  path: '/member/list/add',
                  name: '会员添加',
                  component: './member/list/add/index.tsx',
                  hideInMenu: true,
                },
                {
                  path: '/member/list/detail/:memberId',
                  name: '会员详情',
                  component: './member/list/detail/index.tsx',
                  hideInMenu: true,
                },
                // {
                //   path: '/member/auth',
                //   name: 'member-auth',
                //   // component: './member/auth/index.tsx',
                // },
                {
                  path: '/member/level',
                  name: '会员等级',
                  component: './member/level/index.tsx',
                },
                {
                  path: '/member/tag',
                  name: '会员标签',
                  component: './member/tag/index.tsx',
                },

                {
                  path: '/member/agreement',
                  name: '注册协议',
                  component: './member/agreement/index.tsx',
                },
              ],
            },
            {
              path: '/shop',
              name: '店铺管理',
              icon: 'car',
              routes: [
                {
                  path: '/shop/list',
                  name: '店铺列表',
                  component: './shop/list/index.tsx',
                },
                {
                  path: '/shop/list/add',
                  name: '店铺添加',
                  component: './shop/list/add/index.tsx',
                  hideInMenu: true,
                },
                {
                  path: '/shop/list/manage/:shopId',
                  name: '店铺管理',
                  component: './shop/list/manage/index.tsx',
                  hideInMenu: true,
                },
                {
                  path: '/shop/leve',
                  name: '店铺等级',
                  component: './shop/level/index.tsx',
                },
                {
                  path: '/shop/industry',
                  name: '主营行业',
                  component: './shop/industry/index.tsx',
                },
                {
                  path: '/shop/service',
                  name: '消保服务',
                  component: './shop/service/index.tsx',
                },

                {
                  path: '/shop/store',
                  name: '门店列表',
                  component: './shop/store/index.tsx',
                },
                {
                  path: '/shop/apply',
                  name: '入驻申请',
                  component: './shop/apply/index.tsx',
                },
                {
                  path: '/shop/join-agreement',
                  name: '入驻协议',
                  component: './shop/join_agreement/index.tsx',
                },
                {
                  path: '/shop/join-guide',
                  name: '入驻指南',
                  component: './shop/join_guide/index.tsx',
                },
                {
                  path: '/shop/join-help',
                  name: '入驻帮助',
                  component: './shop/join_help/index.tsx',
                },
              ],
            },
            {
              path: '/promote',
              name: '营销中心',
              icon: 'menu',
              routes: [
                {
                  path: '/promote/shop',
                  name: '店铺营销',
                  component: './promote/shop/index.tsx',
                },
                {
                  path: '/promote/shop/sec-kill',
                  name: '限时秒杀',
                  component: './promote/shop/sec_kill/activity/index.tsx',
                  hideInMenu: true,
                },

                {
                  path: '/promote/shop/sec-kill/goods/add',
                  name: '添加',
                  component: './promote/shop/sec_kill/goods/save.tsx',
                  hideInMenu: true,
                },
                {
                  path: '/promote/shop/sec-kill/goods',
                  name: '秒杀商品',
                  component: './promote/shop/sec_kill/goods/index.tsx',
                  hideInMenu: true,
                },
                {
                  path: '/promote/shop/group-buy',
                  name: '团购',
                  component: './promote/shop/group_buy/index.tsx',
                  hideInMenu: true,
                },

                {
                  path: '/promote/shop/group-buy/:id',
                  name: '',
                  component: './promote/shop/group_buy/save.tsx',
                  hideInMenu: true,
                },
                {
                  path: '/promote/shop/fight-group',
                  name: '拼团',
                  component: './promote/shop/fight_group/index.tsx',
                  hideInMenu: true,
                },
                {
                  path: '/promote/shop/fight-group/:id',
                  name: '',
                  component: './promote/shop/fight_group/save/index.tsx',
                  hideInMenu: true,
                },
                {
                  path: '/promote/shop/coupon',
                  name: '优惠卷',
                  component: './promote/shop/coupon/index/index.tsx',
                  hideInMenu: true,
                },
                {
                  path: '/promote/shop/coupon-receiver/:couponId',
                  name: '领取记录',
                  component: './promote/shop/coupon/receiver/index.tsx',
                  hideInMenu: true,
                },
                {
                  path: '/promote/shop/coupon/:couponId',
                  name: '',
                  component: './promote/shop/coupon/save/index.tsx',
                  hideInMenu: true,
                },
                {
                  path: '/promote/platform',
                  name: '平台营销',
                  component: './promote/platform/index.tsx',
                },
                {
                  path: '/promote/member',
                  name: '会员营销',
                  component: './promote/member/index.tsx',
                },
                {
                  path: '/promote/tool',
                  name: '应用工具',
                  component: './promote/tool/index.tsx',
                },
              ],
            },
            {
              path: '/finance',
              name: '财务管理',
              icon: 'github',
              routes: [
                {
                  path: '/finance/overview',
                  name: '财务概览',
                  component: './finance/overview/index.tsx',
                },
                {
                  path: '/finance/settle',
                  name: '店铺结算',
                  component: './finance/settle/index.tsx',
                },
                {
                  path: '/finance/withdraw',
                  name: '店铺提现',
                  component: './finance/withdraw/index.tsx',
                },
                {
                  path: '/finance/join-fee',
                  name: '入驻费用',
                  component: './finance/join_fee/index.tsx',
                },
              ],
            },
            {
              path: '/statistics',
              name: '信息统计',
              icon: 'chrome',
              routes: [
                {
                  path: '/statistics/overview',
                  name: '统计概况',
                  component: './statistics/overview/index.tsx',
                },
                {
                  path: '/statistics/trade',
                  name: '交易分析',
                  component: './statistics/trade/index.tsx',
                },
                {
                  path: '/statistics/goods',
                  name: '商品分析',
                  component: './statistics/goods/index.tsx',
                },
                {
                  path: '/statistics/member',
                  name: '会员分析',
                  component: './statistics/member/index.tsx',
                },
              ],
            },
            {
              path: '/diy',
              name: 'DIY 装修',
              icon: 'cloud',
              routes: [
                {
                  path: '/diy/homepage',
                  name: '网站主页',
                  component: './diy/homepage/index.tsx',
                },
                {
                  path: '/diy/micro-page',
                  name: '微页面',
                  // component: './diy/micro_page/index.tsx',
                },
                {
                  path: '/diy/bottom-nav',
                  name: '底部导航',
                  component: './diy/bottom_nav/index.tsx',
                },
              ],
            },

            {
              path: '/website',
              name: '网站管理',
              icon: 'project',
              routes: [
                {
                  path: '/website/help',
                  name: '网站帮助',
                  component: './website/help/index.tsx',
                },
                {
                  path: '/website/notice',
                  name: '网站公告',
                  component: './website/notice/index.tsx',
                },
                {
                  path: '/website/ad',
                  name: '广告管理',
                  component: './website/ad/index.tsx',
                },
                {
                  path: '/website/mp',
                  name: 'wx公众号',
                  component: './website/mp/index.tsx',
                },
                {
                  path: '/website/mp-mini',
                  name: 'wx小程序',
                  component: './website/mp_mini/index.tsx',
                },
                {
                  path: '/website/cache',
                  name: '缓存管理',
                  component: './website/cache/index.tsx',
                },
                {
                  path: '/website/addon',
                  name: '插件管理',
                  component: './website/addon/index.tsx',
                },
                {
                  path: '/website/db',
                  name: '数据库管理',
                  component: './website/db/index.tsx',
                },
              ],
            },
            {
              path: '/mall',
              name: '商城管理',
              icon: 'shopping',
              routes: [
                {
                  path: '/mall/receipt-account',
                  name: '收款账户',
                  component: './mall/receipt_account/index.tsx',
                },
                {
                  path: '/mall/register',
                  name: '会员注册',
                  component: './mall/register/index.tsx',
                },
                {
                  path: '/mall/trade',
                  name: '交易设置',
                  component: './mall/trade/index.tsx',
                },
                {
                  path: '/mall/audit',
                  name: '商品审核',
                  component: './mall/audit/index.tsx',
                },
                {
                  path: '/mall/shop-config',
                  name: '店铺设置',
                  component: './mall/shop_config/index.tsx',
                },
                {
                  path: '/mall/after-sale',
                  name: '售后保障',
                  component: './mall/after_sale/index.tsx',
                },
                {
                  path: '/mall/express',
                  name: '物流管理',
                  component: './mall/express/index.tsx',
                },
              ],
            },
            {
              path: '/setting',
              name: '系统设置',
              icon: 'setting',
              routes: [
                {
                  path: '/setting/website',
                  name: '站点设置',
                  component: './setting/website/index.tsx',
                },
                {
                  path: '/setting/copyright',
                  name: '版权设置',
                  component: './setting/copyright/index.tsx',
                },
                {
                  path: '/setting/permission',
                  name: '权限设置',
                  component: './setting/permission/index.tsx',
                },
                {
                  path: '/setting/pay',
                  name: '支付设置',
                  component: './setting/pay/index.tsx',
                },
                {
                  path: '/setting/upload',
                  name: '上传设置',
                  component: './setting/upload/index.tsx',
                },
                {
                  path: '/setting/captcha',
                  name: '验证码设置',
                  component: './setting/captcha/index.tsx',
                },
                {
                  path: '/setting/api',
                  name: 'api安全',
                  component: './setting/api/index.tsx',
                },
                {
                  path: '/setting/default-pic',
                  name: '默认图设置',
                  component: './setting/default_pic/index.tsx',
                },
                {
                  path: '/setting/message',
                  name: '消息管理',
                  component: './setting/message/index.tsx',
                },
                {
                  path: '/setting/sms',
                  name: '短信管理',
                  component: './setting/sms/index.tsx',
                },
                {
                  path: '/setting/email',
                  name: '邮件管理',
                  component: './setting/email/index.tsx',
                },
              ],
            },
            {
              component: './404',
            },
          ],
        },
        {
          component: './404',
        },
      ],
    },
    {
      component: './404',
    },
  ],
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    // ...darkTheme,
    'primary-color': defaultSettings.primaryColor,
  },
  define: {
    REACT_APP_ENV: REACT_APP_ENV || false,
    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
      ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。
  },
  ignoreMomentLocale: true,
  lessLoader: {
    javascriptEnabled: true,
  },
  cssLoader: {
    modules: {
      getLocalIdent: (
        context: {
          resourcePath: string;
        },
        _: string,
        localName: string,
      ) => {
        if (
          context.resourcePath.includes('node_modules') ||
          context.resourcePath.includes('ant.design.pro.less') ||
          context.resourcePath.includes('global.less')
        ) {
          return localName;
        }
        const match = context.resourcePath.match(/src(.*)/);
        if (match && match[1]) {
          const antdProPath = match[1].replace('.less', '');
          const arr = winPath(antdProPath)
            .split('/')
            .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
            .map((a: string) => a.toLowerCase());
          return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
        }
        return localName;
      },
    },
  },
  manifest: {
    basePath: '/',
  },
  proxy: proxy[REACT_APP_ENV || 'dev'],
  chainWebpack: webpackPlugin,
});
